<template>
  <div class="app-container">
    <el-form :model="queryParams"  :inline="true" label-width="90px">
      <el-form-item label="入库单号" >
        <el-input
          v-model="queryParams.roleName"
          placeholder="请输入入库单号"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="产品编号" >
        <el-input
          v-model="queryParams.roleName"
          placeholder="请输入产品编号"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="入库仓库" >
        <el-select v-model="queryParams.mineStatus" placeholder="请选择" multiple style="width: 200px">
          <el-option :value="queryParams.mineStatus" style="height: auto">
            <el-tree :data="treedata" default-expand-all show-checkbox check-strictly node-key="id"
                     ref="tree" highlight-current :props="defaultProps"
                     @check-change="handleCheckChange"></el-tree>
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="入库类型" >
        <el-select v-model="queryParams.value" placeholder="请选择">
          <el-option
            v-for="item in optionslx"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="入库人" >
        <el-input
          v-model="queryParams.roleName"
          placeholder="请输入入库人"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="入库日期">
        <el-date-picker
          v-model="dateRange"
          size="small"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="">搜索</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="roleList" stripe >
      <el-table-column align="center" type="index" label="序号"  width="55"  />
      <el-table-column align="center" label="入库单号" property="jhdh"  ></el-table-column>
      <el-table-column align="center" label="入库产品"   property="biaoti" :show-overflow-tooltip="true"  ></el-table-column>
      <el-table-column align="center" label="入库人" property="cglx" :show-overflow-tooltip="true"  ></el-table-column>
      <el-table-column align="center" label="入库数量"  property="cgsl"  ></el-table-column>
      <el-table-column align="center" label="入库时间" property="cjren" :show-overflow-tooltip="true"  ></el-table-column>
      <el-table-column align="center" label="入库仓库" property="cjren" :show-overflow-tooltip="true"  ></el-table-column>
      <el-table-column align="center" label="入库类型" property="cjren" :show-overflow-tooltip="true"  ></el-table-column>
    </el-table>
    <pagination
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
  import { listRole, getRole, delRole, addRole, updateRole, exportRole, dataScope, changeRoleStatus } from "@/api/system/role";
  import { treeselect } from "@/api/system/dept";

  export default {
    name: "Role",
    data() {
      return {
        treedata: [],
        defaultProps: {
          children: "children",
          label: "label"
        },
        //入库类型
        optionslx:[
          {value:'1',label:'普通入库'},
          {value:'2',label:'采购入库'},
          {value:'3',label:'领用归还'},
          {value:'4',label:'调拨入库'},
          {value:'5',label:'余料入库'},
          {value:'6',label:'旧件返库'},
          {value:'7',label:'盘盈入库'},
        ],

        // 遮罩层
        loading: false,
        // 总条数
        total: 0,
        // 角色表格数据
        roleList: [
          { jhdh:'CGJH2020000265',biaoti:'测试数据',cglx:'网购',cgsl:'99',jhje:'8888',cjrq:'',cjren:'季明聪',beizhu:'备注测试',dqjd:'当前节点',spzt:'1',spjssj:'2020-10-02'},
          { jhdh:'CGJH2020000264',biaoti:'测试数据',cglx:'网购',cgsl:'99',jhje:'8888',cjrq:'',cjren:'季明聪',beizhu:'备注测试',dqjd:'当前节点',spzt:'2',spjssj:'2020-10-02'},
          { jhdh:'CGJH2020000263',biaoti:'测试数据',cglx:'网购',cgsl:'99',jhje:'8888',cjrq:'',cjren:'季明聪',beizhu:'备注测试',dqjd:'当前节点',spzt:'3',spjssj:'2020-10-02'}
        ],
        // 日期范围
        dateRange: [],
        // 状态数据字典
        statusOptions: [
          { value: '1',label: '进行中'},
          { value: '2',label: '已结束'},
          { value: '3',label: '未提交'},
        ],
        // 数据范围选项
        dataScopeOptions: [
          {
            value: "1",
            label: "全部数据权限"
          },
          {
            value: "2",
            label: "自定数据权限"
          },
          {
            value: "3",
            label: "本部门数据权限"
          },
          {
            value: "4",
            label: "本部门及以下数据权限"
          },
          {
            value: "5",
            label: "仅本人数据权限"
          }
        ],
        // 菜单列表
        menuOptions: [],
        // 部门列表
        deptOptions: [],
        // 查询参数
        queryParams: {
          mineStatus:'',
          value:'',
          pageNum: 1,
          pageSize: 10,
          roleName: undefined,
          roleKey: undefined,
          status: undefined,
          checked:true
        },
        // 表单参数
        form: {},
      };
    },
    created() {
      this.getTreeselect()

    },
    methods: {
      handleCheckChange(data, checked, node) {

        var res =this.$refs.tree.getCheckedNodes()
        console.log('res',res);
        var labelArr=[]
        var keyArr = []
        for (var i=0;i<res.length;i++ ){
          labelArr.push(res[i].label)
          keyArr.push(res[i].id)
        }
        console.log('labelArr',labelArr);
        console.log('keyArr',keyArr);
        this.queryParams.mineStatus = labelArr;
      },

      /** 查询部门下拉树结构 */
      getTreeselect() {
        treeselect().then(response => {
          this.treedata = response.data;
        });
      },
      /** 查询角色列表 */
      getList() {
        this.loading = true;
        listRole(this.addDateRange(this.queryParams, this.dateRange)).then(
          response => {
            this.roleList = response.rows;
            this.total = response.total;
            this.loading = false;
          }
        );
      },
      //删除
      handleDelete:function (index,row) {
        this.$confirm('确认撤销？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$message({
            type: 'success',
            message: '撤销成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消撤销'
          });
        });
      },
      //采购计划
      cgjhadd:function () {
        console.log('tianjia')
        this.$router.push({path:'/consumable/cjrkd',query:{userid:'55555'}});
      },
      //详情点击
      xingqing:function (row) {
        console.log(row)
        this.$router.push({path:'/consumable/rkdXQ',query:{userid:row}});
      },

    }
  };
</script>
